import { getArticles, getArticle ,createArticle,updateArticle,delArticle} from "../api/article";
export default {
  // 如果希望你的模块具有更高的封装度和复用性 使用namespaced: true
  namespaced: true,
  state: {
    userData: [],
    page: 1,
    size: 5,
    item: {}
  },
  mutations: {
    SET_TABLE_DATA(state,data) {
      state.userData=data
    },
     SET_ITEM(state, data) {
      state.item = data;
    },
     SET_PAGE(state, data) {
      state.page = data;
    }
  },
  actions: {
     async getList({ commit, state }) {
      // const res = await fetch("http://localhost:3000/contact").then((res) =>
      //   res.json());
      const res = await getArticles({
        page: state.page,
        size: state.size
      })
      commit("SET_TABLE_DATA", res.data);
    },
     async getItem({ commit }, id) {
      const res = await getArticle(id);
      commit("SET_ITEM", res.data);
    },
     async createArticle(context, data) {
      await createArticle(data)
    },
    async updateArticle(context, { id, data }) {
      await updateArticle(id, data)
    },
    async delArticle(context,id) {
      await delArticle(id)
    },
  },
}